package com.ps.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ps.property.ResponseVO;
import com.ps.property.TOtherLike;
import com.ps.service.LikeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author gt
 * @类说明：点赞控制层
 * @date 2020/10/27 19:21
 */
@Api(tags = "点赞接口")
@Controller
@Validated
@Slf4j
public class ProvideLikeController {
    @Autowired
    LikeService likeService;

    @ApiOperation(value = "新增点赞信息接口",notes = "新增点赞信息接口，新增点赞")
    @PostMapping("/likeAdd-provide")
    @ResponseBody
    ResponseVO likeAdd(@Valid @RequestBody TOtherLike tOtherLike) {
        log.info("点赞提供者likeVo={}", tOtherLike);

        return ResponseVO.success(likeService.likeAdd(tOtherLike));
    }

    @ApiOperation(value = "分页查询点赞信息接口",notes = "分页查询点赞信息接口，分页查询点赞")
    @ApiImplicitParams({@ApiImplicitParam(name = "currentPage", value = "当前页数", required = true),@ApiImplicitParam(name = "pageSize", value = "每页行数", required = true)})
    @GetMapping("/likeQuery-provide")
    @ResponseBody
    ResponseVO likeQuery(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        log.info("点赞提供者 当前页={}, 每页行数={}",currentPage,pageSize);

        IPage<TOtherLike> iPage = likeService.likeQuery(currentPage,pageSize);

        return ResponseVO.success(iPage);
    }

    @ApiOperation(value = "根据点赞id修改点赞信息接口",notes = "修改点赞信息接口，修改点赞")
    @ApiImplicitParam(name = "id",value = "点赞ID",required = true)
    @PostMapping("/likeUpdate-provide")
    @ResponseBody
    ResponseVO likeUpdate(@Valid @RequestBody TOtherLike tOtherLike) {
        log.info("点赞提供者要修改的likeVo={}", tOtherLike);

        return ResponseVO.success(likeService.likeUpdate(tOtherLike));
    }

    @ApiOperation(value = "根据点赞id查询点赞信息接口",notes = "查询点赞信息接口，查询点赞")
    @ApiImplicitParam(name = "likeId",value = "点赞ID",required = true)
    @GetMapping("/likeQueryById-provide/{likeId}")
    @ResponseBody
    ResponseVO likeQueryById(@PathVariable int likeId) {
        log.info("点赞提供者要删除的likeId={}",likeId);

        return ResponseVO.success(likeService.likeQueryById(likeId));
    }
}
